<?php
App::uses('AppController', 'Controller');
/**
 * KursyTypes Controller
 *
 * @property KursyType $KursyType
 */
class GalleryCategoriesController extends AppController {


	public function beforeFilter(){
		parent::beforeFilter();
	}
	
	public function beforeRender(){
		parent::beforeRender();
		$this->layout = 'panel';
	}
	
/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->GalleryCategory->recursive = 0;
		$options['order'] = array('GalleryCategory.lp');
		$this->paginate = $options;
		$this->set('kursyTypes', $this->paginate());
	}

/**
 * view method
 *
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->GalleryCategory->id = $id;
		if (!$this->GalleryCategory->exists()) {
			throw new NotFoundException(__d('kursy','Invalid kursy type'));
		}
		$this->set('kursyType', $this->GalleryCategory->read(null, $id));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->request->data['GalleryCategory']['slug'] = strtolower( Inflector::slug($this->request->data['GalleryCategory']['name'],'-') );
			$this->GalleryCategory->create();
			if ($this->GalleryCategory->save($this->request->data)) {
				$this->Session->setFlash(__d('kursy','The kursy type has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__d('kursy','The kursy type could not be saved. Please, try again.'));
			}
		}
// 		$kursies = $this->GalleryCategory->Kursy->find('list');
// 		$this->set(compact('kursies'));
	}

/**
 * edit method
 *
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		$this->GalleryCategory->id = $id;
		if (!$this->GalleryCategory->exists()) {
			throw new NotFoundException(__d('kursy','Invalid kursy type'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			$this->request->data['GalleryCategory']['slug'] = strtolower( Inflector::slug($this->request->data['GalleryCategory']['name'],'-') );
			if ($this->GalleryCategory->save($this->request->data)) {
				$this->Session->setFlash(__d('kursy','The kursy type has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__d('kursy','The kursy type could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->GalleryCategory->read(null, $id);
		}
// 		$kursies = $this->GalleryCategory->Kursy->find('list');
// 		$this->set(compact('kursies'));
	}

/**
 * delete method
 *
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->GalleryCategory->id = $id;
		if (!$this->GalleryCategory->exists()) {
			throw new NotFoundException(__d('kursy','Invalid kursy type'));
		}
		if ($this->GalleryCategory->delete()) {
			$this->Session->setFlash(__d('kursy','Kursy type deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__d('kursy','Kursy type was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
